package com.edais.actions;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.edais.service.ClickCountService;
import com.edais.util.CommonUtil;
import com.edais.util.Consts;
import com.edais.util.JsonUtil;

/**
 * ClassName: ClickCountAction 
 * @Description: TODO
 * @author liaoxinkao
 * @date 2016-3-9
 */
@Controller
@RequestMapping("/click")

public class ClickCountAction {

	@Autowired
	private ClickCountService clickCountService;

	/**
	 * 
	 * @Description: 用户点击率限制
	 * @param request
	 * @param response   
	 * @return
	 * @throws Exception
	 * @author liaoxinkao
	 * @date 2016-3-9
	 */
	@RequestMapping(value = "/getClickInfo")
	public void getClickInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		try {
			// 解密请求参数
			Map<String, String> paramsMap = CommonUtil.decryptParamters(request);

			Map<String, Object> jsonMap = new HashMap<String, Object>();
			
			jsonMap = this.clickCountService.getClickCount(paramsMap);
			// 处理返回结果
			String result = JsonUtil.getJsonStringFromMap(jsonMap);
			CommonUtil.responseJsoNoLog(result, response);
		} catch (Exception e) {
			String result = setClickResult(new HashMap<String, Object>(), Consts.ERROR_CODE, e.getMessage());
			// 处理返回结果
			CommonUtil.responseJsoNoLog(result, response);
			return;
		}
	}

	/**
	 * 设置返回rescode、resmsg_cn
	 * 
	 * */
	public static String setClickResult(Map<String, Object> map, 
			String rescode, String resmsgCn) {
		map.put("clickRescode", rescode);
		map.put("clickResmsg", resmsgCn);
		// 处理返回结果
		return JsonUtil.getJsonStringFromMap(map);
	}
}
